/**
 *  获取url传参工具类
 *  @Authors: LiRui
 *  @date 2017-09-19
 *
 */

var QueryUtils = {
    GetQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    },
    getRootPath_dc: function () {
        var pathName = "../" + window.location.pathname.substring(1);

        var webName = pathName == '' ? '' : pathName.substring(0, pathName.indexOf('/'));
        if (webName == "") {
            return window.location.protocol + '//' + window.location.host;
        }
        else {
            return window.location.protocol + '//' + window.location.host + '/' + webName;
        }
    },
    //当指定data绑定到页面表单
    setFormData: function (select, data) {
        debugger
        if(data == null){
            return;
        }
        var inputs = $(select + " :input");
        $.each(inputs, function (i, input) {
            var val = data[$(input).attr("name")];
            if (val != null) {
                if ($(input).attr("type") == "checkbox" || $(input).attr("type") == "radio") {
                    if ($(input).val() == val + "") {
                        $(input)[0].checked = true;
                    }
                    return true;
                }
                if($(input).attr("type") == "select"){
                    $("[name='"+input+"'] option[value='"+data.input+"']").attr("selected","selected");
                    return true;
                }
                $(input).val(val);
            }
        });
    },

     base:function() {
        debugger
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0,index+1);
    return result;
}
};
